package com.tuanchau.englishtooltip.store;

import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import com.google.appengine.api.datastore.Text;
import com.tuanchau.englishtooltip.Global;

public class Word {
	private final String word;
	private final Text detail;
	private final Entity wordEntity;
	public Word(String word, String detail) {
		this.word = word;
		this.detail = new Text(detail);
		

		//wordEntity = new Entity(Global.TABLE_WORD_NAME, Global.COL_ID);
		Key key =KeyFactory.createKey(Global.TABLE_WORD_NAME, word);
		wordEntity = new Entity(key);
		
		//wordEntity.setProperty(Global.COL_WORD, word);
		wordEntity.setProperty(Global.COL_DETAIL, this.detail);
		
	}
	
	public Word(Entity entity) {
		this.wordEntity = entity;
		word = (String) entity.getProperty(Global.COL_WORD);
		detail = (Text)entity.getProperty(Global.COL_DETAIL);
		
	}
	
	public static Word makeEmptyWord() {
		return new Word("", Global.RESP_NOWORD);
	}
	
	public Entity getEntity() {
		return wordEntity;
	}
	
	public String getWord() {
		return word;
	}
	
	public String toXML() {
		return detail.getValue();
	}
	
	@Override
	public String toString() {
		return word;
	}
	
}
